package com.taxsearch.service.room;

import java.util.List;
import java.util.Map;


import com.taxsearch.dao.room.JingWaiMapper;
import com.taxsearch.dao.room.RoomManagementMapper;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;


/**
 * @description: 
 *
 * @author: 杜一平
 *
 * @create: 2018年9月11日-上午10:37:29
 **/
@Service
public class RoomService {
	// 日志
	public static final Logger logger = LogManager
			.getLogger(RoomService.class);
	// 房间管理以及其他的dao层
	@Autowired
	private RoomManagementMapper roommanagementmapper;
	// 境外相关操作
	@Autowired
	private JingWaiMapper jingWaiMapper;

	/**
	 * 
	 * @Title: judgeRuzhu
	 * @Description: 判断是否可以继续入住 true为可以继续入住 false为不能继续入住
	 * @param: @param hotelId 旅馆id
	 * @param: @param newRoom 入住房间
	 * @param: @return  
	 * @return: boolean   
	 * @throws
	 */
	public boolean judgeRuzhuPerson(String hotelId,String newRoom) {
		try {
			// 查询房间号，精确查询最大入住人数
			List<Map<String, String>> roomList = roommanagementmapper
					.selectRoomJQ(hotelId, newRoom);
			// 获取当天入住人数
			List<Map<String, String>> dangTianRuzhuList = roommanagementmapper
					.selectRuZhuXXJQ(hotelId, newRoom);
			// 查询境外入住
			List<Map<String, String>> jingwaiRuzhuList = jingWaiMapper
					.selectJingWai(hotelId, newRoom);
			
			if ( roomList.size() != 0) {

				Map<String, String> mm = roomList.get(0);
				// 发现一个很奇葩的东西
				// System.out.println("最大人数"+mm.get("maxpeople"));
				JSONObject json = (JSONObject) JSONObject.toJSON(mm);
				// 换房人数是否超限
				if (1 > (Integer.parseInt(json
						.getString("maxpeople")) - dangTianRuzhuList.size()-jingwaiRuzhuList.size())) {
					return false;
				} else {
					return true;
				}
			} else {
				return false;
			}
		} catch (Exception e) {
			logger.error("judgeRuzhu-发生错误!!!!!!!!!!!!!!!!!!!!!!!!", e);
			return false;
		}
	}
}
